﻿//using Microsoft.AspNetCore.Mvc;
//using MiniFox.Infrastructure;
//using MiniFox.Utility;
//using MiniFox.Web.Infrastructure;
//using System.ComponentModel.DataAnnotations;

//namespace MiniFox.Platform.Applications.Web
//{
//    /// <summary>
//    /// 
//    /// </summary>
//    [NoCache, PublicAccessible]
//    public class DataViewController : DataController
//    {
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="name"></param>
//        /// <param name="query"></param>
//        /// <returns></returns>
//        [HttpPost]
//        public override IActionResult PagedQuery([FromRoute, Required] string name, [FromBody] PagedQueryObject query)
//        {
//            var result = PagedQuery(name, query.PageIndex, query.PageSize, query.SortFields, query.Parameters);
//            var response = result.CreateResponse();
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="name"></param>
//        /// <param name="query"></param>
//        /// <returns></returns>
//        [HttpPost]
//        public override IActionResult DataQuery([FromRoute, Required] string name, [FromBody] QueryObject query)
//        {
//            var result = DataQuery(name, query.Parameters);
//            var response = result.CreateResponse();
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// 树查询ss
//        /// </summary>
//        /// <param name="name">查询名称</param>
//        /// <param name="query">查询对象</param>
//        /// <returns></returns>
//        [HttpPost]
//        public override IActionResult TreeQuery([FromRoute, Required] string name, [FromBody] TreeQueryObject query)
//        {
//            var result = TreeDataQuery(name, query.NodeKey, query.SuperKey, query.SortKey, query.GroupKey, query.Parameters);
//            var response = result.CreateResponse();
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="name"></param>
//        /// <param name="query"></param>
//        /// <returns></returns>
//        [HttpPost]
//        public override IActionResult ObjectQuery([FromRoute, Required] string name, [FromBody] QueryObject query)
//        {
//            var result = this.ObjectQuery(name, query.Parameters);
//            var response = result.CreateResponse();
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// 批量操作更新
//        /// </summary>
//        /// <param name="name"></param>
//        /// <param name="dataItems"></param>
//        /// <returns></returns>
//        [HttpPost]
//        public override IActionResult DataOperate([FromRoute, Required] string name, [FromBody] object[] dataItems)
//        {
//            DataSourceFactory factory = this.Component;
//            var dataOperation = factory.GetDataCommand(name);
//            int rowCount = 0;
//            if (dataOperation != null)
//                rowCount = dataOperation.ExecuteOperation(dataItems);
//            var response = rowCount.CreateResponse();
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="name"></param>
//        /// <returns></returns>
//        [HttpGet]
//        public override IActionResult DataQuery([FromRoute, Required] string name)
//        {
//            var parameters = Request.Query.ToDictionary();
//            var result = this.DataQuery(name, parameters);
//            var response = result.CreateResponse();
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// api: data/objectquery/{name}
//        /// 查询并返回单个对象
//        /// </summary>
//        /// <param name="name">查询名</param>
//        /// <returns></returns>
//        [HttpGet]
//        public override IActionResult ObjectQuery([FromRoute, Required] string name)
//        {
//            var parameters = Request.Query.ToDictionary();
//            var result = this.ObjectQuery(name, parameters);
//            var response = result.CreateResponse();
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="name"></param>
//        /// <param name="pageIndex"></param>
//        /// <param name="pageSize"></param>
//        /// <param name="sortField"></param>
//        /// <param name="data"></param>
//        /// <returns></returns>
//        [HttpGet]
//        public override IActionResult PagedQuery([FromRoute, Required] string name, [FromQuery]int? pageIndex, [FromQuery] int? pageSize, [FromQuery] string sortField, [FromQuery] object data)
//        {
//            var parameters = data.ToDictionary();
//            if (parameters == null || parameters.Count <= 0)
//            {
//                parameters = null;
//            }
//            var sortFields = new Dictionary<string, bool>();
//            sortFields.Add(sortField, false);
//            var response = this.PagedQuery(name, pageIndex ?? 1, pageSize ?? 20, sortFields, parameters);
//            return this.View(name, response);
//        }
//        /// <summary>
//        /// 树查询
//        /// </summary>
//        /// <param name="name">查询名称</param>
//        /// <param name="nodeKey">ID字段名</param>
//        /// <param name="superKey">父级ID字段名</param>
//        /// <param name="groupKey">组字段名</param>
//        /// <param name="sortKey">排序字段名</param>
//        /// <returns>返回树型结构集合</returns>
//        [HttpGet]
//        public override IActionResult TreeQuery([FromRoute, Required] string name, [FromQuery, Required] string nodeKey, [FromQuery, Required] string superKey, [FromQuery, Required] string groupKey, [FromQuery, Required] string sortKey)
//        {
//            var result = this.TreeDataQuery(name, nodeKey, superKey, sortKey, groupKey, null);
//            var response = result.CreateResponse();
//            return this.View(name, response);
//        }
//    }
//}
